<?xml version="1.0" encoding="UTF-8"?>
<!-- ===============================================================

This stylesheet adds hash attribute to every <material> tag found
in the SolidWorks material file.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:saxon="http://icl.com/saxon"
                extension-element-prefixes="saxon"
                version="3.0">
<xsl:output omit-xml-declaration="no" indent="yes"/>

<xsl:strip-space elements="*"/>

<xsl:param name="prefix">MHUT</xsl:param>
<xsl:variable name="counter" select="0" saxon:assignable="yes"/>


<xsl:template match="node()|@*">
   <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
   </xsl:copy>
</xsl:template>


<!-- ================================================================
 |
 + ================================================================== -->
<xsl:template match="/">
   <xsl:call-template name="root.messages"/>
   <xsl:apply-templates/>
</xsl:template>

<!-- ================================================================
 |
 + ================================================================== -->
<xsl:template name="root.messages">
   <xsl:message>============================================================</xsl:message>
   <xsl:message> Adding hash key to each technology tag                     </xsl:message>
   <xsl:message>                                                            </xsl:message>
   <xsl:message> AUTHOR : martin.sveda@saabgroup.com                        </xsl:message>
   <xsl:message> USING  :<xsl:value-of select="system-property('xsl:vendor')"/></xsl:message>
   <xsl:message>============================================================</xsl:message>
   <xsl:message>                                                            </xsl:message>
</xsl:template>

<!-- =================================================================
 |   
 |
 +   ================================================================= -->

<!--
<xsl:template match="//materials">
   <xsl:for-each select="classification">
      <xsl:element name="classification">
         <xsl:attribute name="name"><xsl:value-of select="@name" />vvv</xsl:attribute>
      </xsl:element>
      <xsl:copy>
         <xsl:for-each select="material">
            <saxon:assign name="counter" select="$counter+1"/>
            <xsl:element name="material">
               <xsl:attribute name="name"><xsl:value-of select="@name" />, <xsl:value-of select="$prefix"/>-<xsl:number value="$counter" format="000000"/></xsl:attribute>
               <xsl:attribute name="description"><xsl:value-of select="@description" /></xsl:attribute>
               <xsl:attribute name="propertysource"><xsl:value-of select="@propertysource" /></xsl:attribute>
               <xsl:attribute name="appdata"><xsl:value-of select="@appdata"/></xsl:attribute>
               <xsl:apply-templates/>
            </xsl:element>
         </xsl:for-each>
      </xsl:copy>
   </xsl:for-each>      
</xsl:template>
-->



<xsl:template match="//material">
         <saxon:assign name="counter" select="$counter+1"/>
         <xsl:element name="material">
            <xsl:attribute name="name"><xsl:value-of select="@name" />, <xsl:value-of select="$prefix"/>-<xsl:number value="$counter" format="000000"/></xsl:attribute>
            <xsl:attribute name="description"><xsl:value-of select="@description" /></xsl:attribute>
            <xsl:attribute name="propertysource"><xsl:value-of select="@propertysource" /></xsl:attribute>
            <xsl:attribute name="appdata"><xsl:value-of select="@appdata"/></xsl:attribute>
            <xsl:apply-templates/>
         </xsl:element>
</xsl:template>


</xsl:stylesheet> 
